Hands On Continuous Time Modeling With ctsem

Leonard Kosanke & Valentin Kriegmair

Outline

  • Recap
  • Introduction to ctsem
  • Walk-through
  • Excercise
  • Solution

Recap I

What are the assumptions about time in the general cross lagged panel model (GCLPM)?

  1. time prgoresses in discrete steps

  2. equally spaced measurement occasions

  3. subjects are measured at the same time points

Recap II

What are limitations of treating time as a discrete variable when modeling longitudinal data?

  • biased parameter estimates due to:

    • unequally spaced measurement waves in the panel data

    • measurement of individual subjects at each wave spread out over time

  • uncomparable parameter estimates across studies

Recap II

Multivariate stochastic differential equation: \[\begin{gather*} \mathrm{d} \boldsymbol{\eta}_i(t)=\left({\mathbf{A}} \boldsymbol{\eta}_i(t)+\mathbf{B} \mathbf{z}_i+\mathbf{M} \boldsymbol{\chi}_i(t)\right) \mathrm{d} t+\mathbf{G} \mathrm{d} \mathbf{W}_i(t) \end{gather*}\]

Recap II

Multivariate stochastic equation: \[\begin{gather*} \color{red}{\mathrm{d}} \boldsymbol{\eta}_i(\color{red}{t})=\left(\mathbf{A} \boldsymbol{\eta}_i(\color{red}{t})+\mathbf{B} \mathbf{z}_i+\mathbf{M} \boldsymbol{\chi}_i(t)\right) \color{red}{\mathrm{d} t}+\mathbf{G} \color{red}{\mathrm{d}} \mathbf{W}_i(\color{red}{t}) \end{gather*}\] modelling change in latent variables \(\boldsymbol{\eta}_i(t)\) as a function of time over infinitesimal small time steps \(\color{red}{\mathrm{d} t}\)

Recap II

Multivariate stochastic differential equation: \[\begin{gather*} \mathrm{d} \boldsymbol{\eta}_i(t)=\left(\color{red}{\mathbf{A}} \boldsymbol{\eta}_i(t)+\mathbf{B} \mathbf{z}_i+\mathbf{M} \boldsymbol{\chi}_i(t)\right) \mathrm{d} t+\mathbf{G} \mathrm{d} \mathbf{W}_i(t) \end{gather*}\] modelling change as a function of time over infinitesimal small time steps \(\mathrm{d} t\)

\(\color{red}{\mathbf{A}}\): drift matrix with auto effects on the diagonal and cross effects on the off-diagonals (\(\mathbf{A} \in \mathbb{R}^{v \times v}\)).

Recap II

Multivariate stochastic differential equation: \[\begin{gather*} \mathrm{d} \boldsymbol{\eta}_i(t)=\left(\mathbf{A} \boldsymbol{\eta}_i(t)+\mathbf{B} \mathbf{z}_i+\mathbf{M} \boldsymbol{\chi}_i(t)\right) \mathrm{d} t+\mathbf{G} \mathrm{d} \mathbf{W}_i(t) \end{gather*}\] modelling change as a function of time over infinitesimal small time steps \(\mathrm{d} t\)

\(\mathbf{A}\): drift matrix with auto effects on the diagonal and cross effects on the off-diagonals (\(\mathbf{A} \in \mathbb{R}^{v \times v}\)).

\(\mathbf{z_i}\): time independent predictors

\(\boldsymbol{\chi}_i(t)\): time dependent predictors

\(\mathbf{W}_i(t)\): stochastic error term (Wiener process)

\(\mathbf{G}\): diffusion matrix

Recap II

Multivariate stochastic differential equation: \[\begin{gather*} \mathrm{d} \boldsymbol{\eta}_i(t)=\left(\mathbf{A} \boldsymbol{\eta}_i(t)+\mathbf{B} \mathbf{z}_i+\mathbf{M} \boldsymbol{\chi}_i(t)\right) \mathrm{d} t+\mathbf{G} \mathrm{d} \mathbf{W}_i(t) \end{gather*}\] measurement part: \[\begin{gather*} \mathbf{y}(t)=\boldsymbol{\Lambda} \boldsymbol{\eta}(t)+{\boldsymbol{\tau}}+\boldsymbol{\varepsilon}(t) \end{gather*}\] \[\begin{gather*} \boldsymbol{\varepsilon}(t) \sim \mathrm{N}(\mathbf{0}, \mathbf{Θ}) \end{gather*}\]

\(\boldsymbol{\Lambda}\): factor loadings

\(\boldsymbol{\tau}\): intercepts

\(\boldsymbol{\varepsilon}(t)\): measurement error

Introducing ctsem & ctsemOMX

  • R-packages ctsem & ctsemOMX to handle the math
  • ctsem interfaces with Stan
  • ctsemOMX interfaces with OpenMx
  • today we will use ctsemOMX

Data Structure

ctsemOMX uses wide data with time intervals specified in columns:

  Quality_T0 Quality_T1 Quality_T2 dT1 dT2 dT3
1  -8.016139  -8.940450  -8.243518   1   1   1
2  -6.367648  -6.762183  -6.731700   1   1   1
3  -7.927406  -8.518258  -8.907190   1   1   1
4  -5.887097  -7.304229  -5.552340   1   1   1
5  -5.415876 -10.365073  -8.733621   1   1   1
6  -6.408571  -7.434263  -4.577385   1   1   1

(time points can also be interindividually varying)

Function to convert to wideformat:

df_wide <- ctLongToWide(datalong = df_long, id = "id",
  time = "time", manifestNames = c("Quality", ...))

Function to create time intervals:

df_wide <- ctIntervalise(datawide = wideexample, Tpoints = 3, n
  manifest = 2, manifestNames = c("Quality", ...))

Next: Model set-up and interpretation walkthrough